package com.sinosoft.perfect.common.system;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class EncodingInterceptor extends AbstractInterceptor{

	
	private static Logger log = Logger.getLogger(EncodingInterceptor.class);
	
	private static final long serialVersionUID = -805007587165236916L;
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		ActionContext actionContext= invocation.getInvocationContext();
		
		HttpServletRequest request= (HttpServletRequest)actionContext.get(ServletActionContext.HTTP_REQUEST);

		request.setCharacterEncoding("UTF-8");
		
		try {
			return invocation.invoke();
		} catch (Exception e) {
			e.printStackTrace();
			log.error("encoding intercept is error ");
			log.error(e.getMessage());
			throw e;
		}
		
	}

}
